/***************************************************************
 * This script demonstrates how to walk a repository.
 ****************************************************************/
import org.doofer.*

def params = [username: 'test', password: 'test', repository: 'test']
def path = '/test'

// Bootstrap dfc extensions
def doofer = new Doofer()
// Instantiate session helper class
def su = doofer.getSessionUtil(params)

// Open a session then use it
su.withSession {
    // see comment 1
    walkObjects(path: path, recursive: true) { object ->
        // see comment 2
        object.with { println "Found $r_object_type [$object_name]" }
    }
} // Session is automatically released

/*
Comment 1
At this point we're effectivly within the context of an IDfSession object
so we can invoke the IDfSession.walkObjects() method without specifying
the session variable name. The walkObjects() method is one of many methods
that has been injected into the IDfSession interface by Doofer.

Comment 2:
The walkObjects() method accpets a closure which is fired for each
persistent object that is found. We're named this persistent object as
a variable called "object". All Groovy objects provide a with() method
that allows you to use the context of the object. For example,
"hello world".with { reverse() } calls the String.reverse() method. This
same context switching trick is used in Doofer's withSession() method.
We could call object.getObjectName() or the groovier object.objectName() but
we'll take advantage of the property syntax that Doofer supplements the DFC
with so that calls to object_name and r_object_type return the appropriate
attribute values.
 */
